// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   RegisterAction.java

package com.iphaeton.lms.action.user;

import com.iphaeton.exception.BusinessException;
import com.iphaeton.lms.action.organize.OrganizeBizSupportAction;
import com.iphaeton.lms.business.organize.IGroupService;
import com.iphaeton.lms.business.organize.IOrganizeService;
import com.iphaeton.lms.business.role.IRoleService;
import com.iphaeton.lms.pojo.organize.User;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts.action.*;

public class RegisterAction extends OrganizeBizSupportAction
{

    public RegisterAction()
    {
    }

    public ActionForward registerForm(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        java.util.List post;
        java.util.List duty;
        try
        {
            post = group.getGroupList("g", "");
            duty = group.getGroupList("z", "");
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("post", post);
        request.setAttribute("duty", duty);
        return mapping.findForward("register");
    }

    public ActionForward userRegister(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        daf = (DynaActionForm)form;
        User u = new User();
        String id = (String)daf.get("id");
        String userId = (String)daf.get("userId");
        String name = (String)daf.get("name");
        String password = (String)daf.get("password");
        String email = (String)daf.get("email");
        String address = (String)daf.get("address");
        String study = (String)daf.get("study");
        String idcard = (String)daf.get("idcard");
        String birthday = (String)daf.get("birthday");
        String entry = (String)daf.get("entry");
        char sex = ((String) (daf.get("sex"))).trim().charAt(0);
        String state = request.getParameter("state");
        String duty = request.getParameter("duty");
        String post = request.getParameter("post");
        String tel = "";
        String mobil = "";
        if((String)daf.get("tel") != null)
            tel = (String)daf.get("tel");
        if((String)daf.get("mobil") != null)
            mobil = (String)daf.get("mobil");
        try
        {
            com.iphaeton.lms.pojo.organize.Organize org = null;
            if(id != null && !id.equals(""))
                org = organize.findOrganizeById(id);
            else
                org = organize.findRoot();
            u.setUserId(userId);
            u.setName(name);
            u.setPassword(password);
            u.setAddress(address);
            u.setBirthday(birthday);
            u.setEmail(email);
            u.setEntry(entry);
            u.setIdcard(idcard);
            u.setMobil(mobil);
            u.setTel(tel);
            u.setName(name);
            u.setSex(sex);
            u.setState(state.trim().charAt(0));
            u.setStudy(study);
            u = organize.addUser(org, u);
            role.setRole(role.findStudent(), u);
            if(duty != null && !"".equals(duty))
                group.addUser(group.findGroupById(duty), u);
            if(post != null && !"".equals(post))
                group.addUser(group.findGroupById(post), u);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("user", u);
        return mapping.findForward("register_ok");
    }

    private static Logger logger;
    private DynaActionForm daf;
    static Class class$0; /* synthetic field */

    static 
    {
        logger = Logger.getLogger(com.iphaeton.lms.action.user.RegisterAction.class.getName());
    }
}
